<template>
  <Modal
    v-model:active="mediumMeshThickness"
    transfer
    title="中面网格厚度"
    hide-mask
    draggable
    :no-footer="true"
    @close="closeBtn"
    :width="650"
  >
    <div class="box">
      <div class="title">
        <div class="title_color"></div>
        <div class="title_content">选择器</div>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="5">
            <div class="selectorLabel">实体模型:</div>
          </Cell>
          <Cell :width="16">
            <div>
              <div class="selector-container">
                <div class="dropdown-button" @click="toggleDropdown">
                  <img
                    src="../../assets/lowerTriangle.svg"
                    alt=""
                    class="icon imgStyle"
                  />
                </div>
                <div class="dropdown-menu" v-if="dropdownVisible">
                  <div
                    v-for="option in dropdownOptions"
                    :key="option"
                    class="dropdown-item"
                    @click="selectOption(option)"
                  >
                    {{ option }}
                  </div>
                </div>
                <div class="selector-buttons">
                  <button
                    class="selector-button active"
                    @click="selectGeomType"
                  >
                    {{ form.selectedOption }}
                  </button>
                  <button class="selector-button icon-button">
                    <img
                      src="../../assets/delete.svg"
                      alt=""
                      class="icon imgStyle"
                    />
                  </button>
                </div>
              </div>
            </div>
          </Cell>
        </Grid>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="5">
            <div class="selectorLabel">中间网格:</div>
          </Cell>
          <Cell :width="16">
            <div>
              <div class="selector-container">
                <div class="dropdown-button" @click="middleGridDropdown">
                  <img
                    src="../../assets/lowerTriangle.svg"
                    alt=""
                    class="icon imgStyle"
                  />
                </div>
                <div class="dropdown-menu" v-if="middleGridVisible">
                  <div
                    v-for="option in middleGridList"
                    :key="option"
                    class="dropdown-item"
                    @click="selectmiddleGrid(option)"
                  >
                    {{ option }}
                  </div>
                </div>
                <div class="selector-buttons">
                  <button class="selector-button active" @click="selectUnion">
                    {{ form.middleGrid }}
                  </button>
                  <button class="selector-button icon-button">
                    <img
                      src="../../assets/delete.svg"
                      alt=""
                      class="icon imgStyle"
                    />
                  </button>
                </div>
              </div>
            </div>
          </Cell>
        </Grid>
      </div>
      <div class="title">
        <div class="title_color"></div>
        <div class="title_content">厚度输出</div>
      </div>
      <div class="selectorBox">
        <RadioGroup v-model:value="form.thickness" vertical>
          <Radio v-for="item in thicknessList" :key="item" :label="item">
            {{ item }}
          </Radio>
        </RadioGroup>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="5"><div class="selectorLabel">选择属性类型:</div></Cell>
          <Cell :width="16">
            <div>
              <Select
                v-model:value="form.attributeType"
                :options="options"
                clearable
              ></Select>
            </div>
          </Cell>
        </Grid>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="5"><div class="selectorLabel">前缀:</div></Cell>
          <Cell :width="16">
            <div>
              <Input v-model:value="form.prefix" placeholder="请输入"></Input>
            </div>
          </Cell>
        </Grid>
      </div>

      <div class="title">
        <div class="title_color"></div>
        <div class="title_content">选项</div>
      </div>
      <div style="border-bottom: 1px solid #cfcfcf; margin-bottom: 20px">
        <div class="selectorBox">
          <Checkbox v-model:checked="form.minimumThickness">
            最小厚度
          </Checkbox>
        </div>
        <div class="selectorBox">
          <Checkbox v-model:checked="form.maximumThickness">
            最大厚度
          </Checkbox>
        </div>

        <div class="selectorBox">
          <Checkbox v-model:checked="form.averageThickness">
            赋值平均厚度
          </Checkbox>
        </div>
        <div class="selectorBox">
          <Grid :gap="8" :columns="24">
            <Cell :width="8">
              <RadioGroup v-model:value="form.thicknessDistance" vertical>
                <Radio
                  v-for="item in thicknessDistanceList"
                  :key="item"
                  :label="item"
                >
                  {{ item }}
                </Radio>
              </RadioGroup>
            </Cell>
            <Cell :width="16">
              <div>
                <Grid :gap="8" :columns="24">
                  <Cell :width="12">
                    <Input
                      size="small"
                      v-model:value="form.spacingInput"
                      placeholder="请输入"
                    ></Input>
                  </Cell>
                  <Cell :width="12">
                    <Select
                      size="small"
                      v-model:value="form.spacingSelect"
                      :options="spacingOptions"
                      clearable
                    ></Select>
                  </Cell>
                </Grid>
                <Grid :gap="8" :columns="24" style="margin-top: 4px">
                  <Cell :width="12">
                    <Input
                      size="small"
                      v-model:value="form.initial"
                      placeholder="请输入"
                    ></Input>
                  </Cell>
                  <Cell :width="12">
                    <Input
                      size="small"
                      v-model:value="form.fixation"
                      placeholder="请输入"
                    ></Input>
                  </Cell>
                </Grid>
              </div>
            </Cell>
          </Grid>
        </div>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="8">
            <div class="selectorLabel">Thickness decimal</div>
          </Cell>
          <Cell :width="16">
            <Grid :gap="8" :columns="24">
              <Cell :width="12"
                ><Select
                  v-model:value="form.thicknessSelect"
                  :options="spacingOptions"
                  clearable
                ></Select
              ></Cell>
              <Cell :width="12"
                ><Input
                  v-model:value="form.maxIntervalRange"
                  placeholder="请输入"
                ></Input
              ></Cell>
            </Grid>
          </Cell>
        </Grid>
      </div>
      <div class="selectorBox">
        <Grid :gap="8" :columns="24">
          <Cell :width="8">
            <Checkbox v-model:checked="form.setOffset"> 设置偏移 </Checkbox>
          </Cell>
          <Cell :width="16">
            <Grid :gap="8" :columns="24">
              <Cell :width="12"
                ><Select
                  v-model:value="form.offsetSelect"
                  :options="spacingOptions"
                  clearable
                ></Select
              ></Cell>
              <Cell :width="12"
                ><Input
                  v-model:value="form.offsetInput"
                  placeholder="请输入"
                ></Input
              ></Cell>
            </Grid>
          </Cell>
        </Grid>
      </div>
      <div class="foot-box">
        <Button @click="confirm">计算</Button>
        <Button @click="confirm">设置</Button>
      </div>
    </div>
  </Modal>
</template>

<script setup lang="ts">
import {
  Modal,
  CheckboxGroup,
  Button,
  Grid,
  Cell,
  RadioGroup,
  Radio,
  Select,
  Input,
  Checkbox,
  Form,
  FormItem,
} from "cax-ui";
import { storeToRefs } from "pinia";
import { ref } from "vue";
import { useRightMeshEditStore } from "@/UI/store/rightMeshEditStore";
import { _global, useCoreStore } from "@/UI/store";
const rightMeshEditStore = useRightMeshEditStore();
const { mediumMeshThickness } = storeToRefs(rightMeshEditStore);
// 选项状态 - 使用CheckboxGroup
const checkOptions = ref(["lightOrder"]); // 默认选中"光顺"选项
const coreStore = useCoreStore();
const form = ref({
  selectedOption: "实体",
  middleGrid: "单元",
  thickness: "单元厚度",
  attributeType: "1",
  prefix: "AutoThick",
  minimumThickness: false,
  maximumThickness: false,
  averageThickness: false,
  thicknessDistance: "",
  maxIntervalRange: "0.20000000000000001",
  spacingSelect: "1",
  initial: "",
  fixation: "",
  thicknessSelect: "",
  setOffset: false,
  offsetSelect: "",
  offsetInput: "",
});
const thicknessList = ref(["单元厚度", "单元节点厚度", "组件属性"]);
const dropdownVisible = ref(false);
const middleGridVisible = ref(false);
// const selectedOption = ref("");
const dropdownOptions = ref(["实体", "面", "曲线"]);
const middleGridList = ref(["单元", "行", "排"]);
const thicknessDistanceList = ref(["最大厚度距离", "初始厚度与固定间距"]);

const options = [
  {
    label: "Pshell",
    value: "1",
  },
  {
    label: "选项2",
    value: "2",
  },
  {
    label: "选项3",
    value: "3",
  },
];
const spacingOptions = [
  {
    label: "Relative",
    value: "1",
  },
  {
    label: "选项2",
    value: "2",
  },
  {
    label: "选项3",
    value: "3",
  },
];
function selectUnion() {
  // coreStore.setEngineState(2);
}
function selectGeomType() {
  coreStore.setEngineState(2);
}
function toggleDropdown() {
  dropdownVisible.value = !dropdownVisible.value;
}
function selectOption(option: any) {
  form.value.selectedOption = option;
  dropdownVisible.value = false;
}
function middleGridDropdown() {
  middleGridVisible.value = !middleGridVisible.value;
}
function selectmiddleGrid(option: any) {
  form.value.middleGrid = option;
  middleGridVisible.value = false;
}

function confirm() {
  //   rightMeshEditStore.setMediumMeshThickness(false);
  rightMeshEditStore.setFormValue(form.value);
  mediumMeshThickness.value = false;
  _global.Engine.defeature.mid_surface_thickness(form.value).then((result) => {
    // coreStore.setBomInfo(result);
  });
}
function closeBtn() {
  //   rightMeshEditStore.setMediumMeshThickness(false);
  mediumMeshThickness.value = false;
}
</script>

<style scoped>
.box {
  padding: 15px;
}

.imgStyle {
  width: 20px;
  height: 20px;
}
.title {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 16px;
  margin-bottom: 16px;

  .title_color {
    width: 4px;
    height: 12px;
    background: #339af0;
    margin-right: 8px;
  }
  .title_content {
    opacity: 1;
    font-family: PingFang SC;
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    letter-spacing: 0em;
    font-variation-settings: "opsz" auto;
    /* content/主要一级primary */
    /* 样式描述：--vxp-content-color-primary */
    color: #212529;
  }
}
.foot-box {
  margin-top: 40px;
  width: 100%;
  height: 40px;
  text-align: right;
}
.selectorBox {
  padding-left: 80px;
  margin-bottom: 15px;
}
.selector-container {
  position: relative;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.dropdown-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* width: 200px; */
  height: 32px;
  padding: 8px 10px;
  /* background-color: #e6f7a7; */
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 40px;
  width: 200px;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  z-index: 10;
  margin-top: 2px;
}

.dropdown-item {
  padding: 8px 10px;
  cursor: pointer;
}

.dropdown-item:hover {
  background-color: #f5f5f5;
}
.selector-button {
  height: 32px;
  width: 200px;
  padding: 0 15px;
  border: 1px solid #ccc;
  background-color: #fff;
  cursor: pointer;
  outline: none;
}
.selector-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
}
.selector-button.active {
  background-color: #e6f7a7;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  /* flex-grow: 1; */
  font-weight: normal;
}
.icon-button {
  width: 32px;
  padding: 3px 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  border-left: none;
  background-color: #fff;
}
.selectorLabel {
  font-size: 14px;
  height: 32px;
  line-height: 32px;
}
</style>
